<%@ page language="java" pageEncoding="UTF-8"%>
<%@page import="com.shsh.safemanage.action.UserAction"%>
<%@page import="java.util.HashSet"%>
<%@page import="com.shsh.safemanage.model.Role"%>
<%@page import="com.shsh.safemanage.model.User"%>
<%@page import="com.shsh.safemanage.model.ManageGroup"%>
<%@page import="java.util.List"%>
<%@page import="com.shsh.safemanage.action.ActionCreator"%>
<%@page import="com.shsh.safemanage.action.WriteProblemAction"%>
<%@page import="com.shsh.safemanage.util.Constants"%>
<%@page import="com.shsh.safemanage.dao.DaoCreator"%>
<%@page import="com.shsh.safemanage.dao.UserDao"%>
<%@page import="java.util.HashMap"%>
<%@page import="java.util.Set"%>
<%@page import="java.util.Map"%>

<%
{
WriteProblemAction theWriteProblemAction = ActionCreator.createWriteProblemAction();
UserAction theCheckUserAction = ActionCreator.createUserAction();
User theCheckUser = (User) session.getAttribute(Constants.SESSION_USER);

List<ManageGroup> manageGroupList = theWriteProblemAction.getWriterManageGroupList(request);

Role checkUserRole = theCheckUserAction.getUserRole(request);
if ((checkUserRole.getRoleType() & (Constants.ROLE_TYPE_BUZHANG | Constants.ROLE_TYPE_SHEBEIFUBUZHANG | Constants.ROLE_TYPE_SHENGCHANFUBUZHANG
		| Constants.ROLE_TYPE_CHUZHANG | Constants.ROLE_TYPE_FUCHUZHANG)) > 0) {
	ManageGroup leaderManageGroup = new ManageGroup();
	leaderManageGroup.setId(0L);
	leaderManageGroup.setManageGroupName("管理层");
	manageGroupList.add(leaderManageGroup);
}
%>
<table style="margin-left: 10px" border="0" cellpadding="0" cellspacing="0">
	<%
	boolean isBreak = false;
	for (int row = 0; row < 1000; row++) {
		if (isBreak) {
			break;
		}
	%>
	<tr>
	<%
		for (int col = 0; col < 5; col++) {
			int index = row * 5 + col;
			if (index >= manageGroupList.size()) {
				isBreak = true;
				break;
			}
			
			ManageGroup manageGroup = manageGroupList.get(index);
	%>
		<td class="a_text3" width="140" style="border-bottom:1px #E3E3E3 dashed;border-right:1px #E3E3E3 dashed; background: #F9F9F9" valign="top">
			<a style="margin-left: 15px" href="javascript:" 
				onclick="changeDisplayStatus('manageGroupDiv<%=manageGroup.getId()%>')"><%=manageGroup.getManageGroupName()%></a>
			<%
			if (manageGroup.getId() > 0) {
			%>
			<%
				List<User> manageGroupUserList = theWriteProblemAction.getManageGroupMappingUserList(request, manageGroup.getId());
			%>
			<div id="manageGroupDiv<%=manageGroup.getId()%>" style="background: white; display: none;">
			<%
				int i = 0;
				for (User manageGroupUser : manageGroupUserList) {
					i++;
			%>
			<input style="margin-left: 2px" type="checkbox" id="manageGroupUserCheck" value="<%=manageGroupUser.getId()%>" />
			<%=manageGroupUser.getName()%>
			<%
					if (i % 2 == 0) {
			%>
			<br />
			<%
					}
				}
			} else {
				UserDao theUserDao = DaoCreator.createUserDao();
				List<User> leaderUserList = theUserDao.getUsersByRoleType(theCheckUser.getDepartment1ID(), Constants.ROLE_TYPE_ZHUANGZHIZHANG);
				leaderUserList.addAll(theUserDao.getUsersByRoleType(theCheckUser.getDepartment1ID(), 
						Constants.ROLE_TYPE_BUZHANG | Constants.ROLE_TYPE_SHENGCHANFUBUZHANG | Constants.ROLE_TYPE_SHEBEIFUBUZHANG
						| Constants.ROLE_TYPE_CHUZHANG | Constants.ROLE_TYPE_FUCHUZHANG));
			%>
			<div id="manageGroupDiv<%=manageGroup.getId()%>" style="background: white; display: none;">
			<%
				int i = 0;
				for (User manageGroupUser : leaderUserList) {
					i++;
			%>
			<input style="margin-left: 2px" type="checkbox" id="manageGroupUserCheck" value="<%=manageGroupUser.getId()%>" />
			<%=manageGroupUser.getName()%>
			<%
					if (i % 2 == 0) {
			%>
			<br />
			<%
					}
				}
			}
			%>
			</div>
		</td>
	<%
		}
	}
	%>
</table>
<%
}
%>